package com.bite.spring.demo.controller;

import com.bite.spring.demo.model.Person;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/resp")
//@RestController
@Controller
public class RespController {
    @RequestMapping("/r1")
    public String returnPage(){
        return "/index.html";
    }
    @ResponseBody
    @RequestMapping("/r2")
    public String returnData(){
        return "data";
    }
    @ResponseBody
    @RequestMapping("/r3")
    public String returnHtml(){
        return "<h1>我是一级标题</h1>";
    }
    @ResponseBody
    @RequestMapping(value="/r4",produces = "text/plain")
    public String returnText(){
        return "<h1>我是一级标题</h1>";
    }
    @ResponseBody
    @RequestMapping("/r5")
    public Person returnJson(){
        Person person = new Person();
        return person;
    }
    @ResponseBody
    @RequestMapping("/r6")
    public Person setStatus(HttpServletResponse response){
        response.setStatus(404);
        return new Person();
    }
    @ResponseBody
    @RequestMapping("/r7")
    public String setHeader(HttpServletResponse response){

        response.setHeader("myHeader","myHeader");
        return "success";
    }
}
